﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AssetBundleDataReader{
    public Dictionary<uint,AssetBundleData>  infoMap = new Dictionary<uint, AssetBundleData>();
    protected Dictionary<uint,uint> shortName2FullName = new Dictionary<uint, uint>();

    public void Analyze()//分析
    {
        Dictionary<uint, AssetBundleData>.Enumerator enumerator = this.infoMap.GetEnumerator();
        while (enumerator.MoveNext())
        {
            KeyValuePair<uint, AssetBundleData> current = enumerator.Current;
            Analyze(current.Value);
        }
    }

    private void Analyze(AssetBundleData abd)
    {
        if (!abd.isAnalyzed)
        {
            abd.isAnalyzed = true;
            if (abd.dependencies != null)//uint 数组
            {
                abd.dependList = new AssetBundleData[abd.dependencies.Length];
                for (int i = 0; i < abd.dependencies.Length; i++)
                {
                    AssetBundleData assetBundleData = GetAssetBundleInfo(abd.dependencies[i]);
                    abd.dependList[i] = assetBundleData;
                    this.Analyze(assetBundleData);
                }
            }
        }
    }

    public AssetBundleData GetAssetBundleInfo(uint fullName)
    {
        if (fullName != 0 && this.infoMap.ContainsKey(fullName))
        {
            return this.infoMap[fullName];
        }
        return null;
    }

    public AssetBundleData GetAssetBundleInfoByShortName(uint shortName)
    {
        uint fullname = GetFullName(shortName);
        return GetAssetBundleInfo(fullname);
    }

    public uint GetFullName(uint shortName)
    {
        uint ret= 0;
        this.shortName2FullName.TryGetValue(shortName, out ret);
        return ret;
    }

    public virtual void Read()
    {
        
    }
}
